
//////////////////////////////////////////////////////////////////////
#ifndef _DYNLIB_H_
#define _DYNLIB_H_

#include "config.h"
#include <string>

#ifdef __LINUX
#    define DYNLIB_HANDLE void*
#    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
#    define DYNLIB_GETSYM( a, b ) dlsym( a, b )
#    define DYNLIB_UNLOAD( a ) dlclose( a )
#else	
struct HINSTANCE__;
typedef struct HINSTANCE__* hInstance;
#    define DYNLIB_HANDLE hInstance
#    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
#    define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
#endif

namespace KCore
{
	class DynLibManager;
	class _KExport DynLib
	{
	protected:
		std::string _name;
		const char* dynlibError(void);
    public:
  
		DynLib( const char* name,DynLibManager* mgr):_name(name),_hInst(0),_mgr(mgr)
		{

		}
    
        ~DynLib();
        void load();
        void unload();
		const char* getName(void) const { return _name.c_str();}
        void* getSymbol( const char* name) const throw();

		DynLibManager* getMgr()
		{
			return _mgr;
		}
    protected:
		 DYNLIB_HANDLE _hInst;
		 DynLibManager* _mgr;
	};
	
};

#endif

